package com.util;


import com.ysh.gsm.vos.DoubleSerice;
import com.ysh.gsm.vos.SingleReportSerice;
import com.ysh.gsm.vos.ThreeSerice;

import java.util.*;

public class CalculateMRR {
	

	public List<DoubleSerice> calcDoub(int[]y1,int[]y2,int min,int max){
		
		Arrays.sort(y1);
		Arrays.sort(y2);
		int posionY1=0;
		int posionY2=0;
		int tol=y1.length;
		double vy1=0;
		double vy2=0;
		List<DoubleSerice>result=new ArrayList<DoubleSerice>();
		for(int i=min;i<max;i++){
			for(int m=posionY1;m<tol;m++){
				if(y1[m]<=i){
					if(m+1==tol){
						vy1=(double)(m+1)/tol;
						posionY1=m;
						break;
					}
					continue;
				}else{
					vy1=(double)m/tol;
					posionY1=m;
					break;
				}
			}
			for(int n=posionY2;n<tol;n++){
				if(y2[n]<=i){
					if(n+1==tol){
						vy2=(double)(n+1)/tol;
						posionY2=n;
						break;
					}
					continue;
				}else{
					vy2=(double)n/tol;
					posionY2=n;
					break;
				}
			}
			result.add(new DoubleSerice(i,vy1*100,vy2*100));
		}
		
		return result;
	}

	public List<SingleReportSerice> calcSing(int[]pms){		
		int tol=pms.length;
		if(tol<1)return null;
		Arrays.sort(pms);
		List<SingleReportSerice>result=new ArrayList<SingleReportSerice>();
		double y=0;
		for(int i=0;i<tol;i++){
			if(i==tol-1){
				y=(double)(i+1)/tol;
				result.add(new SingleReportSerice(pms[i],y*100));
				break;
			}
			if(pms[i]<pms[i+1]){				
				y=(double)(i+1)/tol;
				result.add(new SingleReportSerice(pms[i],y*100));
			}
		}
		
		return result;
	}
	
	public List<ThreeSerice> calcThree(int[]ta,int[]rxqUp,int[]rxqDn){
		List<ThreeSerice>result=new ArrayList<ThreeSerice>();
		double vy1=0;
		double vy2=0;
		int sumUp=0;
		int sumDn=0;
		int count=0;
		for(int i=0;i<ta.length;i++){
			count++;
			sumUp+=rxqUp[i];
			sumDn+=rxqDn[i];
			if(i==ta.length-1){
				vy1=(double)sumUp/count;
				vy2=(double)sumDn/count;
				result.add(new ThreeSerice(ta[i],vy1,vy2,count));
				break;
			}
			if(ta[i]<ta[i+1]){
				vy1=(double)sumUp/count;
				vy2=(double)sumDn/count;
				result.add(new ThreeSerice(ta[i],vy1,vy2,count));
				sumUp=0;
				sumDn=0;
				count=0;
			}
			
		}
		
		return result;
	}
	
	public static void main(String []ss){
		int[]pms={4,3,2,1,1};
		int[]y1={7,6,5,4,3,2,1,1};
		int[]y2={7,6,5,5,4,3,2,1};
//		List<SingleReportSerice>result=new CalculateMRR().calcPMS(pms);
//		for(SingleReportSerice ser:result){
//			System.out.println(ser.getxFiled()+":"+ser.getyFiled());
//		}
		List<DoubleSerice>result2=new CalculateMRR().calcDoub(y1, y2, 1, 8);
		for (DoubleSerice ds:result2){
			System.out.println(ds.getxFiled()+":"+ds.getyFiled()+" & "+ds.getYyFiled());
		}
		
	}

}
